var app = getApp()
var IP = app.globalData.IP
Page({

  /**
   * 页面的初始数据
   */
  data: {
    //订单id
    id: '',
    selected: '',
    serviceid: '',
    imageurl: '',
    servicename: '',

    //配件总价
    partstotalprice: '',

    //已选配件
    parts: [],

    selectedguzhang: {},
    //手工费
    serviceprice: '',

    //收费详情
    chargedetail: ''

  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    const eventChannel = this.getOpenerEventChannel()
    var that = this
    eventChannel.on('data', function (data) {
      that.setData({
        selected: data.selected,
        serviceid: data.serviceid,
        imageurl: data.imageurl,
        servicename: data.servicename,
        partstotalprice: data.totalprice,
        selectedguzhang: data.selectedguzhang,
        parts: data.parts,
        id: data.id
      })

      console.log(that.data.parts)
      console.log(that.data.selectedguzhang)

    })
    this.setData({
      serviceprice: Number(this.data.selectedguzhang.partprice)
    })


  },

  charge() {
    var chargedetail = "手工费" + String(this.data.serviceprice)
    var parts = this.data.parts
    for (var i = 0; i < parts.length; i++) {
      this.setData({
        chargedetail: chargedetail.concat(parts[i].partname).concat(parts[i].desc).concat(parts[i].partprice).concat(" ")
      })
    }

    wx.request({
      url: `http://${IP}:8080/employee/charge`,
      data: {
        actualpayment: this.data.serviceprice + this.data.partstotalprice,
        chargedetail: this.data.chargedetail,
        id: this.data.id
      }
    })

    wx.request({
      url: `http://${IP}:8080/order/updateStatusTo3/` + this.data.id,
    })




  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})